import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import ticker as ticker
import folium
import branca
from datetime import datetime, timedelta,date
import plotly.express as px
import calmap
import matplotlib.ticker as ticker
from mpl_toolkits.mplot3d import Axes3D
a=pd.read_csv(r'E:\Dataset\Medical.csv', skiprows=2)
pd.set_option('display.max_colwidth', None)
pd.set_option("display.max_columns",None)
pd.set_option("display.max_rows",None)
a=a.drop(['Footnotes'],axis=1)
a.drop(a.loc[53:58].index,inplace=True)
a['Medicare Beneficiaries as a Share of Total Population'] = pd.Series(["{0:.0f}%".format(val * 100/1) for val in a['Medicare Beneficiaries as a Share of Total Population']])
a.head(5)
| Location | Medicare Beneficiaries as a Share of Total Population | |
|---|---|---|
| 0 | United States | 18% |
| 1 | Alabama | 21% |
| 2 | Alaska | 13% |
| 3 | Arizona | 18% |
| 4 | Arkansas | 21% |
a['Medicare Beneficiaries as a Share of Total Population'] = a['Medicare Beneficiaries as a Share of Total Population'].str.rstrip('%')
a['Medicare Beneficiaries as a Share of Total Population']=a['Medicare Beneficiaries as a Share of Total Population'].astype(int)
a.dtypes
Location object Medicare Beneficiaries as a Share of Total Population int32 dtype: object
a.head(5)
| Location | Medicare Beneficiaries as a Share of Total Population | |
|---|---|---|
| 0 | United States | 18 |
| 1 | Alabama | 21 |
| 2 | Alaska | 13 |
| 3 | Arizona | 18 |
| 4 | Arkansas | 21 |
a.shape
(53, 2)
plt.style.use("ggplot")
a= a.sort_values('Medicare Beneficiaries as a Share of Total Population')
ax = a.plot(kind='barh',figsize=(10,10),edgecolor=None)
#f= plt.figure(figsize=(10,10))
#ax=f.add_subplot(1,1,1)
#a.sort_values(by='Medicare Beneficiaries as a Share of Total Population',ascending=True)
ax.set_yticklabels(a['Location'])
#ax.get_yticklabels()[1].set_color("red")
#ax.tick_params(size=5)
#ax=plt.barh(a['Location'],a['Medicare Beneficiaries as a Share of Total Population'])
#ax=plt.tick_params(size=5,labelsize = 10)
for p in ax.patches:
width = p.get_width()
height = p.get_height()
x, y = p.get_xy()
ax.annotate(f'{width:.0f}%', (x + width*1.02, y + height/2), ha='center')
plt.xlabel("Percent",fontsize=18)
plt.title("Medicare Beneficiaries as a Share of Total Population in %",fontsize=20)
plt.tight_layout()
ax.xaxis.set_major_formatter(ticker.PercentFormatter(decimals=0))
#ax.xaxis.set_major_formatter(ticker.PercentFormatter())
#ax.xaxis.set_major_locator(ticker.MultipleLocator())
#ax.xaxis.set_minor_locator(ticker.MultipleLocator())
plt.xlabel("Percent",fontsize=18)
plt.title("Medicare Beneficiaries as a Share of Total Population in %",fontsize=20)
plt.tight_layout()
ax.get_legend().remove()
b=pd.read_csv(r'E:\Dataset\raw_data (3).csv', skiprows=2)
pd.set_option('display.max_colwidth', None)
pd.set_option("display.max_columns",None)
pd.set_option("display.max_rows",None)
b=b.drop(['Footnotes'],axis=1)
b.drop(b.loc[57:68].index,inplace=True)
#b.style.background_gradient(cmap='Blues',subset=["Original Medicare"])\
#.background_gradient(cmap='Reds',subset=["Medicare Advantage"])\
#.background_gradient(cmap='Greens',subset=["Total"])
b.style.format({'Original Medicare': '{:,.0f}','Medicare Advantage': '{:,.0f}','Total': '{:,.0f}'})\
.background_gradient(cmap='Blues',subset=["Original Medicare"])\
.background_gradient(cmap='Reds',subset=["Medicare Advantage"])\
.background_gradient(cmap='Greens',subset=["Total"])
| Location | Original Medicare | Medicare Advantage | Total | |
|---|---|---|---|---|
| 0 | United States | 40,008,858 | 19,860,544 | 59,869,402 |
| 1 | Alabama | 654,501 | 391,201 | 1,045,702 |
| 2 | Alaska | 94,737 | 746 | 95,483 |
| 3 | Arizona | 792,963 | 486,758 | 1,279,721 |
| 4 | Arkansas | 502,380 | 143,714 | 646,094 |
| 5 | California | 3,762,104 | 2,462,728 | 6,224,832 |
| 6 | Colorado | 586,694 | 324,951 | 911,645 |
| 7 | Connecticut | 446,216 | 233,139 | 679,355 |
| 8 | Delaware | 175,265 | 26,391 | 201,656 |
| 9 | District of Columbia | 79,809 | 15,525 | 95,334 |
| 10 | Florida | 2,593,338 | 1,922,172 | 4,515,510 |
| 11 | Georgia | 1,113,944 | 607,604 | 1,721,548 |
| 12 | Hawaii | 148,733 | 120,245 | 268,978 |
| 13 | Idaho | 225,109 | 98,769 | 323,878 |
| 14 | Illinois | 1,750,313 | 489,342 | 2,239,655 |
| 15 | Indiana | 903,265 | 352,022 | 1,255,287 |
| 16 | Iowa | 508,364 | 115,063 | 623,427 |
| 17 | Kansas | 450,288 | 82,931 | 533,219 |
| 18 | Kentucky | 664,989 | 266,487 | 931,476 |
| 19 | Louisiana | 572,878 | 294,948 | 867,826 |
| 20 | Maine | 235,925 | 100,397 | 336,322 |
| 21 | Maryland | 915,375 | 118,007 | 1,033,382 |
| 22 | Massachusetts | 1,042,302 | 283,905 | 1,326,207 |
| 23 | Michigan | 1,301,774 | 762,932 | 2,064,706 |
| 24 | Minnesota | 447,910 | 569,888 | 1,017,798 |
| 25 | Mississippi | 501,276 | 105,370 | 606,646 |
| 26 | Missouri | 840,260 | 398,455 | 1,238,715 |
| 27 | Montana | 188,337 | 39,140 | 227,477 |
| 28 | Nebraska | 298,774 | 45,426 | 344,200 |
| 29 | Nevada | 339,081 | 179,979 | 519,060 |
| 30 | New Hampshire | 260,617 | 35,081 | 295,698 |
| 31 | New Jersey | 1,262,994 | 359,537 | 1,622,531 |
| 32 | New Mexico | 279,122 | 138,316 | 417,438 |
| 33 | New York | 2,207,942 | 1,404,243 | 3,612,185 |
| 34 | North Carolina | 1,322,690 | 643,616 | 1,966,306 |
| 35 | North Dakota | 107,887 | 22,132 | 130,019 |
| 36 | Ohio | 1,469,964 | 860,971 | 2,330,935 |
| 37 | Oklahoma | 608,007 | 134,929 | 742,936 |
| 38 | Oregon | 484,589 | 371,483 | 856,072 |
| 39 | Pennsylvania | 1,625,172 | 1,099,881 | 2,725,053 |
| 40 | Rhode Island | 139,089 | 80,788 | 219,877 |
| 41 | South Carolina | 786,270 | 265,685 | 1,051,955 |
| 42 | South Dakota | 140,854 | 33,163 | 174,017 |
| 43 | Tennessee | 855,439 | 496,096 | 1,351,535 |
| 44 | Texas | 2,632,035 | 1,458,533 | 4,090,568 |
| 45 | Utah | 254,031 | 135,734 | 389,765 |
| 46 | Vermont | 132,287 | 13,566 | 145,853 |
| 47 | Virginia | 1,238,748 | 273,981 | 1,512,729 |
| 48 | Washington | 932,997 | 413,188 | 1,346,185 |
| 49 | West Virginia | 326,613 | 117,257 | 443,870 |
| 50 | Wisconsin | 699,652 | 461,428 | 1,161,080 |
| 51 | Wyoming | 104,955 | 2,701 | 107,656 |
| 52 | American Samoa | 6,725 | 11 | 6,736 |
| 53 | Guam | 16,995 | 0 | 16,995 |
| 54 | Northern Mariana Islands | nan | nan | nan |
| 55 | Puerto Rico | 230,297 | 562,758 | 793,055 |
| 56 | Virgin Islands | 20,825 | 32 | 20,857 |
c=pd.read_csv(r'E:\Dataset\raw_data (4).csv', skiprows=2)
pd.set_option('display.max_colwidth', None)
pd.set_option("display.max_columns",None)
pd.set_option("display.max_rows",None)
c=c.drop(['Footnotes'], axis = 1)
c.drop(c.loc[52:61].index,inplace=True)
c.head()
| Location | Race Categories Include Hispanic Individuals | White % of Cases | White % of Total Population | Black % of Cases | Black % of Total Population | Hispanic % of Cases | Hispanic % of Total Population | Asian % of Cases | Asian % of Total Population | American Indian or Alaska Native % of Cases | American Indian or Alaska Native % of Total Population | Native Hawaiian or Other Pacific Islander % of Cases | Native Hawaiian or Other Pacific Islander % of Total Population | Other % of Cases | Other % of Total Population | Unknown Race % of Cases | Unknown Ethnicity% of Cases | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Alabama | Yes | 0.32 | 0.68 | 0.26 | 0.27 | 0.06 | 0.04 | <.01 | 0.01 | NR | <.01 | NR | NaN | 0.06 | 0.04 | 0.35 | 0.46 |
| 1 | Alaska | Yes | 0.23 | 0.64 | 0.03 | 0.03 | 0.06 | 0.07 | 0.02 | 0.06 | 0.13 | 0.16 | 0.04 | 0.01 | 0.06 | 0.10 | 0.48 | 0.59 |
| 2 | Arizona | NaN | 0.23 | 0.54 | 0.03 | 0.04 | 0.3 | 0.32 | 0.01 | 0.03 | 0.06 | 0.04 | NR | <.01 | 0.03 | 0.02 | 0.34 | 0.34 |
| 3 | Arkansas | Yes | 0.55 | 0.77 | 0.22 | 0.15 | 0.22 | 0.08 | 0.01 | 0.02 | <.01 | 0.01 | 0.04 | <.01 | 0.09 | 0.06 | 0.08 | 0 |
| 4 | California | NaN | 0.11 | 0.37 | 0.03 | 0.05 | 0.4 | 0.39 | 0.04 | 0.15 | <.01 | <.01 | <.01 | <.01 | 0.08 | 0.03 | 0.33 | 0.33 |
c.dtypes
Location object Race Categories Include Hispanic Individuals object White % of Cases object White % of Total Population float64 Black % of Cases object Black % of Total Population object Hispanic % of Cases object Hispanic % of Total Population float64 Asian % of Cases object Asian % of Total Population float64 American Indian or Alaska Native % of Cases object American Indian or Alaska Native % of Total Population object Native Hawaiian or Other Pacific Islander % of Cases object Native Hawaiian or Other Pacific Islander % of Total Population object Other % of Cases object Other % of Total Population float64 Unknown Race % of Cases object Unknown Ethnicity% of Cases object dtype: object
c=c.replace(['NR', '<.01'], [0, .01])
c=c.replace(np.nan,0)
c['White % of Cases'] = c['White % of Cases'].astype(float)
c.sample()
| Location | Race Categories Include Hispanic Individuals | White % of Cases | White % of Total Population | Black % of Cases | Black % of Total Population | Hispanic % of Cases | Hispanic % of Total Population | Asian % of Cases | Asian % of Total Population | American Indian or Alaska Native % of Cases | American Indian or Alaska Native % of Total Population | Native Hawaiian or Other Pacific Islander % of Cases | Native Hawaiian or Other Pacific Islander % of Total Population | Other % of Cases | Other % of Total Population | Unknown Race % of Cases | Unknown Ethnicity% of Cases | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 8 | District of Columbia | Yes | 0.21 | 0.42 | 0.51 | 0.46 | 0.26 | 0.11 | 0.02 | 0.04 | 0.01 | 0.01 | 0.01 | 0 | 0.23 | 0.08 | 0.02 | 0.09 |
c=c.drop(['Race Categories Include Hispanic Individuals'],axis=1)
#c.iloc[:, 1:18].apply(pd.to_numeric).head()
c.loc[:, c.columns != 'Location']=c.loc[:, c.columns != 'Location'].apply(pd.to_numeric)
c.dtypes
Location object White % of Cases float64 White % of Total Population float64 Black % of Cases float64 Black % of Total Population float64 Hispanic % of Cases float64 Hispanic % of Total Population float64 Asian % of Cases float64 Asian % of Total Population float64 American Indian or Alaska Native % of Cases float64 American Indian or Alaska Native % of Total Population float64 Native Hawaiian or Other Pacific Islander % of Cases float64 Native Hawaiian or Other Pacific Islander % of Total Population float64 Other % of Cases float64 Other % of Total Population float64 Unknown Race % of Cases float64 Unknown Ethnicity% of Cases float64 dtype: object
c[c.select_dtypes(include=['number']).columns] *= 100
c.head()
| Location | White % of Cases | White % of Total Population | Black % of Cases | Black % of Total Population | Hispanic % of Cases | Hispanic % of Total Population | Asian % of Cases | Asian % of Total Population | American Indian or Alaska Native % of Cases | American Indian or Alaska Native % of Total Population | Native Hawaiian or Other Pacific Islander % of Cases | Native Hawaiian or Other Pacific Islander % of Total Population | Other % of Cases | Other % of Total Population | Unknown Race % of Cases | Unknown Ethnicity% of Cases | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Alabama | 32.0 | 68.0 | 26.0 | 27.0 | 6.0 | 4.0 | 1.0 | 1.0 | 0.0 | 1.0 | 0.0 | 0.0 | 6.0 | 4.0 | 35.0 | 46.0 |
| 1 | Alaska | 23.0 | 64.0 | 3.0 | 3.0 | 6.0 | 7.0 | 2.0 | 6.0 | 13.0 | 16.0 | 4.0 | 1.0 | 6.0 | 10.0 | 48.0 | 59.0 |
| 2 | Arizona | 23.0 | 54.0 | 3.0 | 4.0 | 30.0 | 32.0 | 1.0 | 3.0 | 6.0 | 4.0 | 0.0 | 1.0 | 3.0 | 2.0 | 34.0 | 34.0 |
| 3 | Arkansas | 55.0 | 77.0 | 22.0 | 15.0 | 22.0 | 8.0 | 1.0 | 2.0 | 1.0 | 1.0 | 4.0 | 1.0 | 9.0 | 6.0 | 8.0 | 0.0 |
| 4 | California | 11.0 | 37.0 | 3.0 | 5.0 | 40.0 | 39.0 | 4.0 | 15.0 | 1.0 | 1.0 | 1.0 | 1.0 | 8.0 | 3.0 | 33.0 | 33.0 |
jj=c.iloc[:,0]
sk=c.iloc[:,1]
pk=c.iloc[:,2]
kl=c.iloc[:,3]
jk=c.iloc[:,4]
fk=c.iloc[:,5]
wek=c.iloc[:,6]
gh=c.iloc[:,7]
ds=c.iloc[:,8]
gf=c.iloc[:,9]
gr=c.iloc[:,10]
cv=c.iloc[:,11]
hf=c.iloc[:,12]
sc=c.iloc[:,13]
wd=c.iloc[:,14]
ty=c.iloc[:,15]
uj=c.iloc[:,16]
index=np.arange(len(c))
plt.figure(figsize=(17,10))
#graph=plt.barh(y=index,width=sk)
#graph1=plt.barh(y=index,width=pk,left=sk)
graph=plt.bar(x=index,height=sk)
graph1=plt.bar(x=index,height=pk,bottom=sk)
graph2=plt.bar(x=index,height=kl,bottom=pk+sk)
graph3=plt.bar(x=index,height=jk,bottom=sk+pk+kl)
grap4=plt.bar(x=index,height=fk,bottom=sk+pk+kl+jk)
graph5=plt.bar(x=index,height=wek,bottom=sk+pk+kl+jk+fk)
grap6=plt.bar(x=index,height=gh,bottom=sk+pk+kl+jk+fk+wek)
graph7=plt.bar(x=index,height=ds,bottom=sk+pk+kl+jk+fk+wek+gh)
grap8=plt.bar(x=index,height=gf,bottom=sk+pk+kl+jk+fk+wek+gh+ds)
graph9=plt.bar(x=index,height=gr,bottom=sk+pk+kl+jk+fk+wek+gh+ds+gf)
graph10=plt.bar(x=index,height=cv,bottom=sk+pk+kl+jk+fk+wek+gh+ds+gf+gr)
graph11=plt.bar(x=index,height=hf,bottom=sk+pk+kl+jk+fk+wek+gh+ds+gf+gr+cv)
graph12=plt.bar(x=index,height=sc,bottom=sk+pk+kl+jk+fk+wek+gh+ds+gf+gr+cv+hf)
graph13=plt.bar(x=index,height=wd,bottom=sk+pk+kl+jk+fk+wek+gh+ds+gf+gr+cv+hf+sc)
graph14=plt.bar(x=index,height=ty,bottom=sk+pk+kl+jk+fk+wek+gh+ds+gf+gr+cv+hf+sc+wd)
graph15=plt.bar(x=index,height=uj,bottom=sk+pk+kl+jk+fk+wek+gh+ds+gf+gr+cv+hf+sc+wd+ty)
plt.xticks(index,jj,rotation=90)
plt.tight_layout()
plt.show()
d=pd.read_csv(r'E:\Dataset\raw_data (6).csv', skiprows=2)
pd.set_option('display.max_colwidth', None)
pd.set_option("display.max_columns",None)
pd.set_option("display.max_rows",None)
d=d.drop(['Footnotes'], axis = 1)
d.drop(d.loc[57:].index,inplace=True)
d.head()
| Location | Number of COVID-19 Cases | COVID-19 Cases per 1,000,000 Population | Deaths from COVID-19 | COVID-19 Deaths per 1,000,000 Population | COVID-19 Fatality Rate | |
|---|---|---|---|---|---|---|
| 0 | United States | 6,187,336 | 18850.0 | 187,464 | 571.0 | 0.030298 |
| 1 | Alabama | 130,393 | 26594.0 | 2,266 | 462.0 | 0.017378 |
| 2 | Alaska | 5,584 | 7633.0 | 40 | 55.0 | 0.007163 |
| 3 | Arizona | 204,681 | 28120.0 | 5,171 | 710.0 | 0.025264 |
| 4 | Arkansas | 63,081 | 20903.0 | 861 | 285.0 | 0.013649 |
d.dtypes
Location object Number of COVID-19 Cases object COVID-19 Cases per 1,000,000 Population float64 Deaths from COVID-19 object COVID-19 Deaths per 1,000,000 Population float64 COVID-19 Fatality Rate float64 dtype: object
#d.loc[:, d.columns != 'Location']=d.loc[:, d.columns != 'Location'].apply(pd.to_numeric)
#d['Number of COVID-19 Cases']= (d['Number of COVID-19 Cases'].str.split()).apply(lambda x: float(d[:,1].replace(',','')))
d=d.replace(",","",regex=True)
d.sample()
| Location | Number of COVID-19 Cases | COVID-19 Cases per 1,000,000 Population | Deaths from COVID-19 | COVID-19 Deaths per 1,000,000 Population | COVID-19 Fatality Rate | |
|---|---|---|---|---|---|---|
| 46 | Utah | 53839 | 16793.0 | 419 | 131.0 | 0.007782 |
d.loc[:, d.columns != 'Location']=d.loc[:, d.columns != 'Location'].apply(pd.to_numeric)
d.dtypes
Location object Number of COVID-19 Cases int64 COVID-19 Cases per 1,000,000 Population float64 Deaths from COVID-19 int64 COVID-19 Deaths per 1,000,000 Population float64 COVID-19 Fatality Rate float64 dtype: object
d.style.background_gradient(cmap='Blues',subset=["Number of COVID-19 Cases"])\
.background_gradient(cmap='Reds',subset=["COVID-19 Cases per 1,000,000 Population"])\
.background_gradient(cmap='Greens',subset=["Deaths from COVID-19"])\
.background_gradient(cmap='Purples',subset=["COVID-19 Deaths per 1,000,000 Population"])\
.background_gradient(cmap='Pastel1_r',subset=["COVID-19 Fatality Rate"])\
.format("{:.0f}",subset=["COVID-19 Deaths per 1,000,000 Population","Deaths from COVID-19","COVID-19 Cases per 1,000,000 Population","Number of COVID-19 Cases"])
| Location | Number of COVID-19 Cases | COVID-19 Cases per 1,000,000 Population | Deaths from COVID-19 | COVID-19 Deaths per 1,000,000 Population | COVID-19 Fatality Rate | |
|---|---|---|---|---|---|---|
| 0 | United States | 6187336 | 18850 | 187464 | 571 | 0.030298 |
| 1 | Alabama | 130393 | 26594 | 2266 | 462 | 0.017378 |
| 2 | Alaska | 5584 | 7633 | 40 | 55 | 0.007163 |
| 3 | Arizona | 204681 | 28120 | 5171 | 710 | 0.025264 |
| 4 | Arkansas | 63081 | 20903 | 861 | 285 | 0.013649 |
| 5 | California | 728415 | 18435 | 13560 | 343 | 0.018616 |
| 6 | Colorado | 58267 | 10118 | 1955 | 339 | 0.033552 |
| 7 | Connecticut | 53365 | 14968 | 4468 | 1253 | 0.083725 |
| 8 | Delaware | 17752 | 18230 | 606 | 622 | 0.034137 |
| 9 | District of Columbia | 14186 | 20101 | 611 | 866 | 0.043071 |
| 10 | Florida | 640211 | 29808 | 11750 | 547 | 0.018353 |
| 11 | Georgia | 279354 | 26311 | 5931 | 559 | 0.021231 |
| 12 | Hawaii | 9202 | 6499 | 79 | 56 | 0.008585 |
| 13 | Idaho | 32927 | 18425 | 372 | 208 | 0.011298 |
| 14 | Illinois | 247260 | 19513 | 8360 | 660 | 0.033811 |
| 15 | Indiana | 97884 | 14540 | 3350 | 498 | 0.034224 |
| 16 | Iowa | 68203 | 21617 | 1141 | 362 | 0.016729 |
| 17 | Kansas | 44878 | 15404 | 473 | 162 | 0.010540 |
| 18 | Kentucky | 50885 | 11390 | 976 | 218 | 0.019181 |
| 19 | Louisiana | 151473 | 32583 | 5035 | 1083 | 0.033240 |
| 20 | Maine | 4633 | 3447 | 134 | 100 | 0.028923 |
| 21 | Maryland | 110831 | 18332 | 3789 | 627 | 0.034187 |
| 22 | Massachusetts | 121758 | 17665 | 9100 | 1320 | 0.074738 |
| 23 | Michigan | 116280 | 11643 | 6797 | 681 | 0.058454 |
| 24 | Minnesota | 78966 | 14002 | 1899 | 337 | 0.024048 |
| 25 | Mississippi | 85939 | 28876 | 2558 | 859 | 0.029765 |
| 26 | Missouri | 91175 | 14856 | 1604 | 261 | 0.017593 |
| 27 | Montana | 8019 | 7503 | 114 | 107 | 0.014216 |
| 28 | Nebraska | 35469 | 18336 | 404 | 209 | 0.011390 |
| 29 | Nevada | 70712 | 22957 | 1375 | 446 | 0.019445 |
| 30 | New Hampshire | 7368 | 5419 | 432 | 318 | 0.058632 |
| 31 | New Jersey | 193422 | 21776 | 15978 | 1799 | 0.082607 |
| 32 | New Mexico | 25812 | 12310 | 791 | 377 | 0.030645 |
| 33 | New York | 437971 | 22514 | 32982 | 1695 | 0.075306 |
| 34 | North Carolina | 174253 | 16614 | 2839 | 271 | 0.016292 |
| 35 | North Dakota | 12973 | 17024 | 150 | 197 | 0.011562 |
| 36 | Ohio | 128444 | 10988 | 4248 | 363 | 0.033073 |
| 37 | Oklahoma | 62040 | 15679 | 846 | 214 | 0.013636 |
| 38 | Oregon | 27336 | 6481 | 470 | 111 | 0.017193 |
| 39 | Pennsylvania | 142495 | 11131 | 7735 | 604 | 0.054283 |
| 40 | Rhode Island | 22243 | 20997 | 1055 | 996 | 0.047431 |
| 41 | South Carolina | 123325 | 23953 | 2846 | 553 | 0.023077 |
| 42 | South Dakota | 14596 | 16499 | 170 | 192 | 0.011647 |
| 43 | Tennessee | 160597 | 23516 | 1837 | 269 | 0.011439 |
| 44 | Texas | 646545 | 22298 | 13300 | 459 | 0.020571 |
| 45 | USVI | 1150 | nan | 16 | nan | 0.013913 |
| 46 | Utah | 53839 | 16793 | 419 | 131 | 0.007782 |
| 47 | Vermont | 1642 | 2631 | 58 | 93 | 0.035323 |
| 48 | Virginia | 124738 | 14614 | 2662 | 312 | 0.021341 |
| 49 | Washington | 75856 | 9962 | 1945 | 255 | 0.025641 |
| 50 | West Virginia | 11042 | 6161 | 245 | 137 | 0.022188 |
| 51 | Wisconsin | 77856 | 13372 | 1146 | 197 | 0.014719 |
| 52 | Wyoming | 3941 | 6809 | 41 | 71 | 0.010403 |
| 53 | American Samoa | 0 | nan | 0 | nan | 0.000000 |
| 54 | Guam | 1619 | nan | 14 | nan | 0.008647 |
| 55 | Northern Mariana Islands | 57 | nan | 2 | nan | 0.035088 |
| 56 | Puerto Rico | 34241 | 10721 | 455 | 142 | 0.013288 |
e=pd.read_csv(r'E:\Dataset\raw_data (14).csv', skiprows=2)
pd.set_option('display.max_colwidth', None)
pd.set_option("display.max_columns",None)
pd.set_option("display.max_rows",None)
e.drop(e.loc[52:].index,inplace=True)
#e.drop(e.index[0], inplace=True)
e.drop(e.head(1).index,inplace=True)
e.reset_index(drop=True,inplace=True)
e.sample(5)
| Location | Total Hospitals | |
|---|---|---|
| 13 | Illinois | 187.0 |
| 43 | Texas | 523.0 |
| 3 | Arkansas | 88.0 |
| 16 | Kansas | 139.0 |
| 15 | Iowa | 118.0 |
abbreviation=pd.read_csv(r'E:\Downloads\csvData.csv')
abbreviation.head()
| State | Abbrev | Code | |
|---|---|---|---|
| 0 | Alabama | Ala. | AL |
| 1 | Alaska | Alaska | AK |
| 2 | Arizona | Ariz. | AZ |
| 3 | Arkansas | Ark. | AR |
| 4 | California | Calif. | CA |
newdf= pd.concat([e,abbreviation['Code']], axis = 1, levels=0).sort_index(axis=1)
newdf.head()
| Code | Location | Total Hospitals | |
|---|---|---|---|
| 0 | AL | Alabama | 101.0 |
| 1 | AK | Alaska | 21.0 |
| 2 | AZ | Arizona | 83.0 |
| 3 | AR | Arkansas | 88.0 |
| 4 | CA | California | 359.0 |
fig = px.choropleth(newdf, # Input Pandas DataFrame
locations="Code", # DataFrame column with locations
color_continuous_scale="Viridis",
color='Total Hospitals',
#range_color=(0, 12), # DataFrame column with color values
hover_name="Location", # DataFrame column hover info
locationmode = 'USA-states') # Set to plot as US States
fig.update_layout(
title_text = 'Total Number of Hospitals in each State', # Create a Title
geo_scope='usa', # Plot only the USA instead of globe
)
f=pd.read_csv(r'E:\Dataset\raw_data (15).csv', skiprows=2)
pd.set_option('display.max_colwidth', None)
pd.set_option("display.max_columns",None)
pd.set_option("display.max_rows",None)
f.drop(f.loc[52:].index,inplace=True)
f.drop(f.head(1).index,inplace=True)
f.reset_index(drop=True,inplace=True)
f.head()
| Location | Total Hospital Beds | Beds per 1,000 Population | |
|---|---|---|---|
| 0 | Alabama | 15278.0 | 3.1 |
| 1 | Alaska | 1636.0 | 2.2 |
| 2 | Arizona | 13846.0 | 1.9 |
| 3 | Arkansas | 9517.0 | 3.2 |
| 4 | California | 72511.0 | 1.8 |
fig, ax = plt.subplots()
#vals = np.array([[60., 32.], [37., 40.], [29., 10.]])
labels = f['Location']
sizes = f['Total Hospital Beds']
labels_vegefruit = f['Location']
sizes_vegefruit = f['Beds per 1,000 Population']
size=0.3
cmap = plt.get_cmap("tab20c")
outer_colors = cmap(np.arange(3)*4)
inner_colors = cmap(np.array([1, 2, 5, 6, 9, 10]))
#ax.pie(vals.sum(axis=1), radius=3, colors=outer_colors,
# wedgeprops=dict(width=size, edgecolor='w'))
ax.pie(sizes, labels=labels, radius=3, colors=outer_colors,rotatelabels=True,
wedgeprops=dict(width=size, edgecolor='w'))
#ax.pie(vals.flatten(), radius=1-size, colors=inner_colors,
# wedgeprops=dict(width=size, edgecolor='w'))
ax.pie(sizes_vegefruit, labels=labels_vegefruit, radius=2, colors=inner_colors,rotatelabels=True,
wedgeprops=dict(width=size, edgecolor='w'))
#ax.set(aspect="equal", title='Total Hospital Beds and Beds/1k Population')
#ax.set(aspect="equal")
plt.title('Total Hospital Beds and Beds/1k Population',y=2)
#plt.tight_layout()
plt.show()
fig, ax = plt.subplots(figsize=(10,8),subplot_kw=dict(aspect="equal"))
res= f['Total Hospital Beds']
#vals = np.array([[60., 32.], [37., 40.], [29., 10.]])
labels = f['Location']
sizes = f['Total Hospital Beds']
cmap = plt.get_cmap("tab20c")
outer_colors = cmap(np.arange(3)*4)
wedges,texts=ax.pie(sizes,labels=labels, colors=outer_colors,startangle=90,rotatelabels=True,
wedgeprops=dict(width=0.5, edgecolor='w'))
bbox_props = dict(boxstyle="square,pad=0.3", fc="w", ec="k", lw=0.72)
kw = dict(arrowprops=dict(arrowstyle="-"),
bbox=bbox_props, zorder=0, va="center")
for i, p in enumerate(wedges):
ang = (p.theta2 - p.theta1)/2. + p.theta1
y = np.sin(np.deg2rad(ang))
x = np.cos(np.deg2rad(ang))
horizontalalignment = {-1: "right", 1: "left"}[int(np.sign(x))]
connectionstyle = "angle,angleA=0,angleB={}".format(ang)
kw["arrowprops"].update({"connectionstyle": connectionstyle})
ax.annotate(res[i], xy=(x, y), xytext=(1.35*np.sign(x), 1.4*y),
horizontalalignment=horizontalalignment, **kw)
plt.title('Total Hospital Beds',y=1.2)
plt.tight_layout()
plt.show()
g=pd.read_csv(r'E:\Dataset\raw_data (16).csv', skiprows=2)
pd.set_option('display.max_colwidth', None)
pd.set_option("display.max_columns",None)
pd.set_option("display.max_rows",None)
g.drop(g.loc[52:].index,inplace=True)
g.sample(5)
| Location | State/Local Government | Non-Profit | For-Profit | Total | |
|---|---|---|---|---|---|
| 32 | New Mexico | 0.3 | 0.7 | 0.7 | 1.8 |
| 28 | Nebraska | 0.5 | 2.9 | 0.1 | 3.6 |
| 9 | District of Columbia | NaN | 3.5 | 0.9 | 4.4 |
| 0 | United States | 0.3 | 1.7 | 0.4 | 2.4 |
| 15 | Indiana | 0.4 | 1.9 | 0.4 | 2.7 |
plt.style.use('seaborn')
g=g.replace(np.nan,0)
plt.figure(figsize=(10,8))
state=g['State/Local Government']
non=g['Non-Profit']
forp=g['For-Profit']
loc=g['Location']
plt.scatter(state,loc,edgecolor='black',linewidth=1,alpha=0.75,label='State\Local Government Hospital')
plt.scatter(non,loc,edgecolor='black',linewidth=1,alpha=0.75,label='Non-Profit Hospital')
plt.scatter(forp,loc,edgecolor='black',linewidth=1,alpha=0.75,label='For-Profit Hospital')
plt.legend()
plt.xlabel('Hospital Beds/1k population')
plt.title('Hospitals Beds/1k population by Ownership type')
plt.tight_layout()
plt.show()
h=pd.read_csv(r'E:\Dataset\raw_data (17).csv', skiprows=2)
pd.set_option('display.max_colwidth', None)
pd.set_option("display.max_columns",None)
pd.set_option("display.max_rows",None)
h.drop(h.loc[52:].index,inplace=True)
h=h.replace(np.nan,0)
h.loc[:, h.columns != 'Location']=h.loc[:, h.columns != 'Location'].astype(int)
state=h['State/Local Government']
nonprofit=h['Non-Profit']
forprofit=h['For-Profit']
location=h['Location']
fig = plt.figure(figsize=(10,8))
ax = fig.add_subplot(111, projection='3d')
colors = ['r', 'g', 'b']
yticks = [2, 1, 0]
for c, k in zip(colors, yticks):
xs = location
ys = state
cs = [c] * len(xs)
cs[0] = 'c'
ax.bar(xs, ys, zs=k, zdir='y', color=cs, alpha=0.8)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.set_yticks(yticks)
plt.show()
i=pd.read_csv(r'E:\Dataset\raw_data (21).csv', skiprows=2)
pd.set_option('display.max_colwidth', None)
pd.set_option("display.max_columns",None)
pd.set_option("display.max_rows",None)
i.drop(i.loc[52:].index,inplace=True)
j=pd.read_csv(r'E:\Dataset\raw_data (22).csv', skiprows=2)
pd.set_option('display.max_colwidth', None)
pd.set_option("display.max_columns",None)
pd.set_option("display.max_rows",None)
j.drop(j.loc[52:].index,inplace=True)
j=j.drop(['Footnotes'],axis=1)
k=pd.read_csv(r'E:\Dataset\raw_data (23).csv', skiprows=2)
pd.set_option('display.max_colwidth', None)
pd.set_option("display.max_columns",None)
pd.set_option("display.max_rows",None)
k.drop(k.loc[52:].index,inplace=True)
DF= pd.concat([i,j,k], axis = 1, levels=0).sort_index(axis=1)
DF.sample()
| ICU Beds | ICU Beds per 10,000 Population | Location | Location | Location | Primary Care Physicians | Specialist Physicians | Total | Total Residents | |
|---|---|---|---|---|---|---|---|---|---|
| 9 | 401.0 | 6.0 | District of Columbia | District of Columbia | District of Columbia | 3204.0 | 4271.0 | 7475.0 | 667900.0 |
DF = DF.loc[:,~DF.columns.duplicated()]
DF.sample()
| ICU Beds | ICU Beds per 10,000 Population | Location | Primary Care Physicians | Specialist Physicians | Total | Total Residents | |
|---|---|---|---|---|---|---|---|
| 34 | 3168.0 | 3.2 | North Carolina | 13587.0 | 15231.0 | 28818.0 | 10044400.0 |
DF.set_index('Location',inplace=True)
DF.rename(columns = {'Total':'Total Physicians'}, inplace = True)
DF.head()
| ICU Beds | ICU Beds per 10,000 Population | Primary Care Physicians | Specialist Physicians | Total Physicians | Total Residents | |
|---|---|---|---|---|---|---|
| Location | ||||||
| United States | 85247.0 | 2.7 | 486405.0 | 535601.0 | 1022006.0 | 318498500.0 |
| Alabama | 1870.0 | 3.9 | 5845.0 | 6320.0 | 12165.0 | 4752600.0 |
| Alaska | 130.0 | 1.8 | 1063.0 | 835.0 | 1898.0 | 709100.0 |
| Arizona | 1742.0 | 2.5 | 8633.0 | 9446.0 | 18079.0 | 7004300.0 |
| Arkansas | 856.0 | 2.9 | 3563.0 | 3726.0 | 7289.0 | 2921300.0 |
DF.dtypes
ICU Beds float64 ICU Beds per 10,000 Population float64 Primary Care Physicians float64 Specialist Physicians float64 Total Physicians float64 Total Residents float64 dtype: object
DF.style.background_gradient(cmap='Blues',subset=["ICU Beds"])\
.background_gradient(cmap='Reds',subset=["ICU Beds per 10,000 Population"])\
.format("{:.1f}")\
.background_gradient(cmap='Greens',subset=["Primary Care Physicians"])\
.background_gradient(cmap='Purples',subset=["Specialist Physicians"])\
.background_gradient(cmap='Pastel1_r',subset=["Total Physicians"])\
.background_gradient(cmap='YlOrBr',subset=["Total Residents"])\
.format("{:.0f}",subset=["Primary Care Physicians","Specialist Physicians","Total Physicians","ICU Beds","Total Residents"])
| ICU Beds | ICU Beds per 10,000 Population | Primary Care Physicians | Specialist Physicians | Total Physicians | Total Residents | |
|---|---|---|---|---|---|---|
| Location | ||||||
| United States | 85247 | 2.7 | 486405 | 535601 | 1022006 | 318498500 |
| Alabama | 1870 | 3.9 | 5845 | 6320 | 12165 | 4752600 |
| Alaska | 130 | 1.8 | 1063 | 835 | 1898 | 709100 |
| Arizona | 1742 | 2.5 | 8633 | 9446 | 18079 | 7004300 |
| Arkansas | 856 | 2.9 | 3563 | 3726 | 7289 | 2921300 |
| California | 8131 | 2.1 | 54580 | 59418 | 113998 | 38745900 |
| Colorado | 1770 | 3.2 | 7368 | 7381 | 14749 | 5555200 |
| Connecticut | 731 | 2.1 | 7124 | 8733 | 15857 | 3466300 |
| Delaware | 249 | 2.7 | 1591 | 1611 | 3202 | 937700 |
| District of Columbia | 401 | 6.0 | 3204 | 4271 | 7475 | 667900 |
| Florida | 6226 | 3.0 | 27791 | 30012 | 57803 | 20843500 |
| Georgia | 2703 | 2.6 | 12675 | 13002 | 25677 | 10212800 |
| Hawaii | 219 | 1.6 | 1882 | 1825 | 3707 | 1354800 |
| Idaho | 333 | 1.9 | 1669 | 1362 | 3031 | 1719600 |
| Illinois | 3426 | 2.8 | 22318 | 21782 | 44100 | 12438400 |
| Indiana | 2358 | 3.6 | 8221 | 8758 | 16979 | 6487100 |
| Iowa | 622 | 2.0 | 4627 | 4201 | 8828 | 3056800 |
| Kansas | 878 | 3.1 | 4097 | 3868 | 7965 | 2814700 |
| Kentucky | 1447 | 3.3 | 5519 | 6522 | 12041 | 4320300 |
| Louisiana | 1518 | 3.4 | 6392 | 7622 | 14014 | 4519300 |
| Maine | 288 | 2.2 | 2524 | 2282 | 4806 | 1299500 |
| Maryland | 1227 | 2.1 | 11084 | 14062 | 25146 | 5870800 |
| Massachusetts | 1555 | 2.3 | 15815 | 21139 | 36954 | 6659900 |
| Michigan | 2749 | 2.8 | 18763 | 20921 | 39684 | 9770000 |
| Minnesota | 1277 | 2.3 | 8891 | 9483 | 18374 | 5489000 |
| Mississippi | 931 | 3.2 | 3245 | 3434 | 6679 | 2879400 |
| Missouri | 2092 | 3.5 | 9594 | 11124 | 20718 | 5934500 |
| Montana | 248 | 2.4 | 1184 | 1141 | 2325 | 1034000 |
| Nebraska | 548 | 2.9 | 2936 | 2763 | 5699 | 1868900 |
| Nevada | 1118 | 3.7 | 3093 | 3130 | 6223 | 2983400 |
| New Hampshire | 252 | 1.9 | 2064 | 2265 | 4329 | 1310300 |
| New Jersey | 1882 | 2.2 | 14907 | 15984 | 30891 | 8728300 |
| New Mexico | 460 | 2.2 | 2967 | 2923 | 5890 | 2045300 |
| New York | 4420 | 2.3 | 41076 | 50765 | 91841 | 19016900 |
| North Carolina | 3168 | 3.2 | 13587 | 15231 | 28818 | 10044400 |
| North Dakota | 278 | 3.8 | 1162 | 919 | 2081 | 730600 |
| Ohio | 3622 | 3.2 | 19942 | 23228 | 43170 | 11355900 |
| Oklahoma | 1164 | 3.1 | 4862 | 4747 | 9609 | 3816100 |
| Oregon | 837 | 2.0 | 6053 | 6191 | 12244 | 4110800 |
| Pennsylvania | 3643 | 2.9 | 24884 | 27444 | 52328 | 12388100 |
| Rhode Island | 279 | 2.8 | 2665 | 2661 | 5326 | 1014000 |
| South Carolina | 1459 | 3.0 | 6478 | 6594 | 13072 | 4929800 |
| South Dakota | 150 | 1.8 | 1106 | 969 | 2075 | 848700 |
| Tennessee | 2309 | 3.5 | 8904 | 10241 | 19145 | 6586400 |
| Texas | 7149 | 2.6 | 31085 | 34548 | 65633 | 28024000 |
| Utah | 687 | 2.2 | 3169 | 3771 | 6940 | 3105900 |
| Vermont | 94 | 1.6 | 1135 | 1225 | 2360 | 600600 |
| Virginia | 2007 | 2.5 | 11713 | 11826 | 23539 | 8182100 |
| Washington | 1493 | 2.0 | 11148 | 11167 | 22315 | 7368000 |
| West Virginia | 643 | 3.7 | 2941 | 2897 | 5838 | 1752300 |
| Wisconsin | 1506 | 2.7 | 8616 | 9291 | 17907 | 5662800 |
| Wyoming | 102 | 1.8 | 650 | 540 | 1190 | 560300 |
n=pd.read_csv(r'E:\Dataset\usa_county_wise.csv')
n.head(5)
| UID | iso2 | iso3 | code3 | FIPS | Admin2 | Province_State | Country_Region | Lat | Long_ | Combined_Key | Date | Confirmed | Deaths | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 16 | AS | ASM | 16 | 60.0 | NaN | American Samoa | US | -14.2710 | -170.1320 | American Samoa, US | 1/22/20 | 0 | 0 |
| 1 | 316 | GU | GUM | 316 | 66.0 | NaN | Guam | US | 13.4443 | 144.7937 | Guam, US | 1/22/20 | 0 | 0 |
| 2 | 580 | MP | MNP | 580 | 69.0 | NaN | Northern Mariana Islands | US | 15.0979 | 145.6739 | Northern Mariana Islands, US | 1/22/20 | 0 | 0 |
| 3 | 630 | PR | PRI | 630 | 72.0 | NaN | Puerto Rico | US | 18.2208 | -66.5901 | Puerto Rico, US | 1/22/20 | 0 | 0 |
| 4 | 850 | VI | VIR | 850 | 78.0 | NaN | Virgin Islands | US | 18.3358 | -64.8963 | Virgin Islands, US | 1/22/20 | 0 | 0 |
n=n.drop(['Country_Region','Admin2','code3'],axis=1)
n.shape
(538065, 11)
newdf=n.head(200000)
fig = px.scatter_geo(newdf, locations='FIPS', locationmode='ISO-3',
lat= 'Lat',
lon='Long_',
color=np.power(newdf["Confirmed"],0.3)-2 ,
size= np.power(newdf["Confirmed"]+1,0.3)-1,
hover_name='Combined_Key',
hover_data=['Confirmed'],
range_color= [0, max(np.power(newdf["Confirmed"],0.3))],
projection="albers usa", animation_frame="Date",
color_continuous_scale=px.colors.sequential.Plasma,
title='COVID-19: Progression of spread'
)
fig.update_coloraxes(colorscale="hot")
fig.update(layout_coloraxis_showscale=False)
fig.show()